class Solution {
    public String addBinary(String a, String b) {
        int alen = a.length();
        int blen = b.length();

        int x = alen-1;
        int y = blen-1;
        int flag = 0;
        int num = x>=y?x:y;
        char[] str = new char[num];
        num--;
        while(x>=0&&y>=0) {
            if(a.charAt(x) == '1' && b.charAt(y) == '1') {
                str[num] = '0';
                flag = 1;
            }

            if((a.charAt(x) == '1' && b.charAt(y) == '0') || (a.charAt(x) == '0' && b.charAt(y) == '1')) {
                
                if(1 == flag) {
                    str[num] = '0';
                    flag = 0;
                }else {
                    str[num] = '1';
                }
            }
            if((a.charAt(x) == '0' && b.charAt(y) == '0') ) {
                if(1 == flag) {
                    str[num] = '1';
                    flag = 0;
                }else {
                    str[num] = '0';
                }
            }
            num--;
            x--;
            y--;
        }
        String str1 = new String(str);
        System.out.println(str1.length());
        System.out.println(str1);
        return str1;
        //int c = x>=y?x:y;
       // return str1.subString(num-c,num+1);
    }
}